home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / c80tcog.lbr / RANDI2.C < prev    next >
Text File  |  1985-08-09  |  640b  |  38 lines

  1. /*    randi2 - unsigned 16-bit pseudo-random numbers        */
  2. /*
  3.     based on Knuth, Donald E. "The Art of Computer Programming"
  4. Vol 2, 2nd. ed. 1981.
  5.  
  6.     William G. Hutchison, Jr.
  7.     P.O. Box 278
  8.     Exton, PA 19341-0278
  9.     U.S.A.
  10.  
  11.     CompuServe 70665,1307
  12.     CO CNODE #1080
  13.  
  14.  */
  15.  
  16. #include "randi1.c"    /* above */
  17.  
  18. randi2(x)
  19. unsigned *x;
  20. {
  21. #define TSIZE 55
  22. static unsigned r, t[TSIZE];
  23. static int p= -1;
  24. static int q= 0;
  25.  
  26. if    (p < 0) {
  27.     for    (p= q= TSIZE-1; q >= 0; q--)
  28.         t[q]= randi1(*x);
  29.     q= 23;
  30.     }
  31.  
  32. r= (t[p]+= t[q]);
  33. if    (p-- == 0)    p= TSIZE-1;
  34. if    (q-- == 0)    q= TSIZE-1;
  35. return    (r);
  36. #undef TSIZE
  37. }                /* end of randi2        */
  38.